/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.assertj.ohos.api.components.element;

import ohos.agp.components.element.Element;
import ohos.agp.utils.Rect;
import org.assertj.core.api.AbstractAssert;

import static org.assertj.core.api.Assertions.assertThat;

/** 元素断言 */
public abstract class ElementAssert<S extends ElementAssert<S, A>, A extends Element>
    extends AbstractAssert<S, A> {
    protected ElementAssert(A actual, Class<S> selfType) {
    super(actual, selfType);
    }

    /**
    * 已绑定
    *
    * @param bounds 区域
    * @return S
    */
    public S hasBounds(Rect bounds) {
    isNotNull();
    Rect actualBounds = actual.getBounds();
    assertThat(actualBounds) //
        .overridingErrorMessage("Expected bounds <%s> but was <%s>.", bounds, actualBounds) //
        .isEqualTo(bounds);
    return myself;
    }

    /**
     * 回调
     *
     * @param callback  元素改变回调
     * @return S
     */
    public S hasCallback(Element.OnChangeListener callback) {
    isNotNull();
    Element.OnChangeListener actualCallback = actual.getCallback();
    assertThat(actualCallback) //
        .overridingErrorMessage("Expected callback <%s> but was <%s>.", callback, actualCallback) //
        .isSameAs(callback);
    return myself;
    }

    /**
    * 具有内在高度
    *
    * @param height 高
    * @return S
    */
    public S hasIntrinsicHeight(int height) {
    isNotNull();
    int actualHeight = actual.getHeight();
    assertThat(actualHeight) //
        .overridingErrorMessage("Expected intrinsic height <%s> but was <%s>.", height,
            actualHeight) //
        .isEqualTo(height);
    return myself;
    }

    /**
    * 具有内在宽度
    *
    * @param width 宽
    * @return S
    */
    public S hasIntrinsicWidth(int width) {
    isNotNull();
    int actualWidth = actual.getWidth();
    assertThat(actualWidth) //
        .overridingErrorMessage("Expected intrinsic width <%s> but was <%s>.", width,
            actualWidth) //
        .isEqualTo(width);
    return myself;
    }

    /**
    * 具有最小高度
    *
    * @param height 高
    * @return S
    */
    public S hasMinimumHeight(int height) {
    isNotNull();
    int actualHeight = actual.getMinHeight();
    assertThat(actualHeight) //
        .overridingErrorMessage("Expected minimum height <%s> but was <%s>.", height,
            actualHeight) //
        .isEqualTo(height);
    return myself;
    }

    /**
    * 具有最小宽度
    *
    * @param width 宽
    * @return S
    */
    public S hasMinimumWidth(int width) {
    isNotNull();
    int actualHeight = actual.getMinWidth();
    assertThat(actualHeight) //
        .overridingErrorMessage("Expected minimum width <%s> but was <%s>.", width, actualHeight) //
        .isEqualTo(width);
    return myself;
    }

    /**
    * 是否处于状态
    *
    * @return S
    */
    public S isStateful() {
    isNotNull();
    assertThat(actual.isStateful()) //
        .overridingErrorMessage("Expected to be stateful but was not.") //
        .isTrue();
    return myself;
    }

    /**
    * 是否处于非有状态
    *
    * @return S
    */
    public S isNotStateful() {
    isNotNull();
    assertThat(actual.isStateful()) //
        .overridingErrorMessage("Expected to not be stateful but was.") //
        .isFalse();
    return myself;
    }

    /**
    * 是否显示
    *
    * @return S
    */
    public S isVisible() {
    isNotNull();
    assertThat(actual.getVisible()) //
        .overridingErrorMessage("Expected to be visible but was not.") //
        .isTrue();
    return myself;
    }

    /**
    * 是否隐藏
    *
    * @return S
    */
    public S isNotVisible() {
    isNotNull();
    assertThat(actual.getVisible()) //
        .overridingErrorMessage("Expected to not be visible but was.") //
        .isFalse();
    return myself;
    }

    /**
    * alpha
    *
    * @param alpha 阿尔法
    * @return S
    */
    public S hasAlpha(int alpha) {
    isNotNull();
    int actualAlpha = actual.getAlpha();
    assertThat(actualAlpha) //
        .overridingErrorMessage("Expected alpha <%s> but was <%s>.", alpha, actualAlpha) //
        .isEqualTo(alpha);
    return myself;
    }

    /**
    * 是否自动镜像
    *
    * @return S
    */
    public S isAutoMirrored() {
    isNotNull();
    assertThat(actual.isInheritDirection()) //
        .overridingErrorMessage("Expected to be auto mirrored but was not.") //
        .isTrue();
    return myself;
    }

    /**
    * 是否自动镜像
    *
    * @return S
    */
    public S isNotAutoMirrored() {
    isNotNull();
    assertThat(actual.isInheritDirection()) //
        .overridingErrorMessage("Expected to not be auto mirrored but was.") //
        .isFalse();
    return myself;
    }
}
